
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/23/2013 11:41:47
-- Generated from EDMX file: C:\Users\Nick\Documents\Visual Studio 2012\Projects\ModelResourceManager\ModelResourceManager\ResourceManagerEF.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RMDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Resources]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Resources];
GO
IF OBJECT_ID(N'[dbo].[Queues]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Queues];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [UserId] uniqueidentifier  NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Skype] nvarchar(max)  NOT NULL,
    [Role] nvarchar(max)  NOT NULL,
    [Login] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [MessageTimeSpan] time  NOT NULL,
    [Online] bit  NOT NULL
);
GO

-- Creating table 'Resources'
CREATE TABLE [dbo].[Resources] (
    [ResourceId] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [StartTime] time  NOT NULL,
    [EndTime] time  NOT NULL,
    [Locked] bit  NOT NULL,
    [TimeOfUsing] time  NOT NULL,
    [UserCount] int  NOT NULL,
    [OnlyAutoTime] bit  NOT NULL
);
GO

-- Creating table 'Queues'
CREATE TABLE [dbo].[Queues] (
    [QueueId] uniqueidentifier  NOT NULL,
    [ResourceId] uniqueidentifier  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [StartTime] datetime  NOT NULL,
    [FinishTime] datetime  NOT NULL,
    [MessageTime] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [UserId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [ResourceId] in table 'Resources'
ALTER TABLE [dbo].[Resources]
ADD CONSTRAINT [PK_Resources]
    PRIMARY KEY CLUSTERED ([ResourceId] ASC);
GO

-- Creating primary key on [QueueId] in table 'Queues'
ALTER TABLE [dbo].[Queues]
ADD CONSTRAINT [PK_Queues]
    PRIMARY KEY CLUSTERED ([QueueId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------